const mongoose = require("mongoose");
const leaveSchema = mongoose.Schema({
  orderNo: String, //申请单号
  applyType: Number, //申请类型 1事假 2调休 3年假
  startTime: { type: Date, default: Date.now },
  endTime: { type: Date, default: Date.now },
  applyUser: {
    //审批人
    userId: String,
    userName: String,
    userEmail: String,
  },
  leaveTime: String, //休假时长
  reasons: String, //申请原因
  auditUsers: String, //完整审批人
  curAuditUserName: String, //当前审批人
  auditFlows: [
    //审批流
    {
      userId: String,
      userName: String,
      userEmail: String,
    },
  ],
  auditLogs: [
    //审批日志
    {
      userId: String,
      userName: String,
      createTime: Date,
      remark: String, //备注
      action: String, //通过还是不通过
    },
  ],
  applyState: { type: Number, default: 1 }, //审批状态  1: "待审批",2: "审批中",3: "审批拒绝",4: "审批通过",5: "作废",
  createTime: {
    //申请时间
    type: Date,
    default: Date.now(),
  }, //创建时间
  updateTime: {
    type: Date,
    default: Date.now(),
  }, //更新时间
});

module.exports = mongoose.model("leaves", leaveSchema, "leaves");
